package com.qf.agro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.ResultInfo;
import com.qf.agro.common.SysUserHolder;
import com.qf.agro.mapper.DeviceMapper;
import com.qf.agro.pojo.SmartDevice;
import com.qf.agro.pojo.SysUser;
import com.qf.agro.service.DeviceService;
import io.swagger.v3.oas.annotations.servers.Server;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 10202
 * @version V1.0
 * @Project smart-agriculture-parent
 * @Package com.qf.agro.service.impl
 * @Date 2023/7/5 22:12
 */
@Service
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceMapper deviceMapper;
    @Override
    public ResultInfo getPage(Integer pageNum, Integer pageSize, Long facilitiesId, String name) {

        Page<SmartDevice> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmartDevice> lqw =new LambdaQueryWrapper<>();
        SysUser sysUser = SysUserHolder.get();
        if(sysUser!=null){
            lqw.eq(sysUser.getCompanyId()!=null,SmartDevice::getCompanyId,sysUser.getCompanyId());
        }
        lqw.like(StringUtils.isNotEmpty(name),SmartDevice::getDeviceName,name);
      page =  deviceMapper.selectPage(page,lqw);

        return ResultInfo.success(page);
    }
}
